<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>
<body>
    <div class="nav">
        <span>
            五子棋对战
        </span>
        <span class="spacer"></span>
        <a href="register.html">注册</a>
    </div>
    <div class="login-container">
        <!-- 登录界面对话框 -->
        <div class="login-dialog">
            <!-- 提示信息 -->
            <h3>登录</h3>
            <!-- 一行内容 -->
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username">
            </div>
            <!-- 一行内容 -->
            <div class="row">
                <span>密码</span>
                <input type="password" id="password">
            </div>
            <!-- 提交按钮 -->
            <div class="row">
                <button id="submit" onclick="mysub()">提交</button>
            </div>


        </div>
    </div>
    <script>
        function mysub() {
            var username = jQuery("#username");
            var password = jQuery("#password");
            if(username.val()=="") {
                alert("请输入用户名!");
                username.focus();
                return;
            }
            if(password.val()=="") {
                alert("请输入密码!")
                password.focus();
                return;
            }
    
            jQuery.ajax({
                url:"/login",
                type:"POST",
                data:{"username":username.val(),"password":password.val()},
                success:function(result) {
                    if(result!=null && result.code == 200 &&result.data.userId > 0) {
                        alert("登录成功!");
                        location.href = "/game_hall.html";
                    }else {
                        alert("登录失败!");
                    }
                },
                error:function() {
                    alert("登录失败!1")
                }
            });
        
        }
    </script>
</body>
</html>